#include <bits/stdc++.h>
typedef long int uint;
using namespace std;
/* file.in
3
5 3 2
*/
/* result should be
1
*/
int main() 
{
    freopen("file.in","r",stdin);
    uint n, t1, t2, count = 1;
    vector<uint> queue;
    cin >> n;
    
    for (uint i = 0; i < n; i++)
    {
        cin >> t1;
        queue.push_back(t1);
    }
    t1 = queue.front();
    if(queue.size()==1)
        cout << t1;
    else
    {
        while(queue.size()!=1)
        {
            queue.erase(queue.begin());
            if (count == n)
            {
                n--;
                count = 1;
                t1 = queue.front();
                continue;
            }
            t2 = queue.front();
            queue.push_back(t2 - t1);
            count++;
            t1 = t2;
        }
        cout << queue.front();
    }

    return 0;
}
